////////////////////////////////////////////////////////////////////////////////
// Filename: cameraclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "cameraclass.h"
#include <stdio.h>

CameraClass::CameraClass() : dV( D3DXVECTOR3(0,0,1) ),
					dU( D3DXVECTOR3(0,1,0) ),
					eye( D3DXVECTOR3(0,0,-10) ),
					view( D3DXVECTOR3(0,0,1) ),
					up( D3DXVECTOR3(0,1,0) ),
					forward( D3DXVECTOR3(0,0,1) ),
					strafeRight( D3DXVECTOR3(1,0,0) )
{
	m_rotationX = 0.0f;
	m_rotationY = 0.0f;
	m_rotationZ = 0.0f;
	m_movementForward = 0.0f;
	m_movementRight = 0.0f;
	D3DXMatrixIdentity(&m_viewMatrix);
}


CameraClass::CameraClass(const CameraClass& other)
{
}


CameraClass::~CameraClass()
{
}


void CameraClass::SetPosition(float x, float y, float z)
{
	eye.x = x;
	eye.y = y;
	eye.z = z;
	return;
}
void CameraClass::SetMovement(float forward, float right)
{
	m_movementForward = forward;
	m_movementRight = right;
	return;
}

void CameraClass::SetRotation(float x, float y, float z)
{
	m_rotationX = x;
	m_rotationY = y;
	m_rotationZ = z;
	return;
}


D3DXVECTOR3 CameraClass::GetPosition()
{
	return D3DXVECTOR3(eye.x, eye.y, eye.z);
}


void CameraClass::Render()
{
	//create rotation matrix
	D3DXMatrixRotationYawPitchRoll( &rotationMatrix, m_rotationY * 0.0174532925f, m_rotationZ * 0.0174532925f, 0 );

	//create new view and up vectors
	D3DXVec3TransformCoord( &view, &dV, &rotationMatrix );
	D3DXVec3TransformCoord( &up, &dU, &rotationMatrix );
	
	//create new forward and strafe vectors
	D3DXVec3Normalize( &forward, &view );
	D3DXVec3Cross( &strafeRight, &up, &view );
	D3DXVec3Normalize( &strafeRight, &strafeRight );
	eye += m_movementForward * forward + m_movementRight * strafeRight;

	//take into account eye position
	view = eye + view;

	//update view matrix
	D3DXMatrixLookAtLH( &m_viewMatrix, &eye, &view, &up );

	return;
}


void CameraClass::GetViewMatrix(D3DXMATRIX& viewMatrix)
{
	viewMatrix = m_viewMatrix;
	return;
}